Windows 上 OpenSSH 配置文件的位置 您所在的位置:网站首页 window openssh如何设置home目录 Windows 上 OpenSSH 配置文件的位置

Windows 上 OpenSSH 配置文件的位置

2024-05-01 20:29| 来源: 网络整理| 查看: 265

OpenSSH 安装后,执行一些额外的配置步骤。

确保 OpenSSH 文件夹包含在系统路径环境变量中:

C:\Windows\System32\OpenSSH\如果作为 Windows 可选功能 C:\Program Files\OpenSSH\安装 如果通过 OpenSSH 下载安装 将两个服务设置为自动启动:

# PowerShell Admin # Config services sshd and ssh-agent # for start automatic when logon Set-Service sshd -StartupType Automatic Set-Service ssh-agent -StartupType Automatic

如果您安装了带有可选功能的 OpenSSH,则 Windows 会创建一个新的防火墙规则,以允许通过端口 22 对 SSH 进行入站访问。如果您通过下载安装了 OpenSSH,则使用以下命令创建防火墙规则:

# PowerShell Admin # Add FireWall Rules for OpenSSH Server New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server (sshd)' ` -Enabled True -Direction Inbound -Protocol TCP ` -Action Allow -LocalPort 22

启动 sshd 服务以生成 SSH 密钥:

# PowerShell Admin Start-Service sshd

SSH 密钥和配置文件位于C:\ProgramData\ssh隐藏文件夹中。SSH 使用的默认 shell 是 Windows 命令 shell。这需要更改为 PowerShell:

# PowerShell Admin New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell ` -Value "C:\Program Files\PowerShell\6\pwsh.exe" -PropertyType String -Force

现在,当您通过 SSH 连接到系统时,PowerShell Core 将启动并成为默认 shell。如果需要,您还可以将默认外壳程序设置为 Windows PowerShell。

Windows 上的 OpenSSH 存在一个错误。它不适用于带有空格的路径,例如 PowerShell Core 可执行文件的路径!解决方法是创建一个符号链接来创建 OpenSSH 可以使用的路径:

# PowerShell Admin New-Item -ItemType SymbolicLink -Path C:\pwsh -Target 'C:\Program Files\PowerShell\6'

在 sshd_config文件中,取消注释以下行:

PubkeyAuthentication yes PasswordAuthentication yes

在其他子系统行之前添加此行:

Subsystem powershell C:\pwsh\pwsh.exe -sshs -NoLogo -NoProfile

这告诉 OpenSSH 运行 PowerShell Core。

注释掉这一行:

AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keys

保存对 sshd_config 文件的更改后,重新启动服务:

# PowerShell Admin Restart-Service sshd Start-Service ssh-agent

对配置文件进行任何更改后,您需要重新启动 sshd 服务。



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有